package cn.usian.controller;

import cn.usian.common.R;
import cn.usian.dto.SetmealDto;
import cn.usian.service.SetmealDishService;
import cn.usian.service.SetmealService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @Autowired
    private SetmealDishService setmealDishService;


    @GetMapping("/page")
    public R findPage(Integer page, Integer pageSize, String name) {
        //检查参数
        if (page <= 0 || pageSize <= 0) {
            return null;//参数异常
        }
        Page<SetmealDto> page1 = setmealService.findPage(page, pageSize, name);
        return R.success(page1);
    }


    /**
     * 新增套餐
     *
     * @param setmealDto
     * @return
     */
    @PostMapping
    public R add(@RequestBody SetmealDto setmealDto) {
        //检查参数
        if (setmealDto == null) {
            return null;  //参数异常
        }
        //调用方法添加套餐
        setmealService.saveWithDish(setmealDto);

        return R.success("新增套餐成功");

    }


}
